Skip to content

ValueFilterProxyModel

Base classes

Name Children Inherits
SortFilterProxyModel
prettyqt.core.sortfilterproxymodel
Support for sorting and filtering data passed between another model and a view.

⋔ Inheritance diagram

graph TD
  2211274329["itemmodels.ValueFilterProxyModel"]
  2548039224["core.SortFilterProxyModel"]
  2431222121["core.AbstractProxyModelMixin"]
  3882849576["core.AbstractItemModelMixin"]
  3227531497["core.ObjectMixin"]
  2751680898["builtins.object"]
  153997648["QtCore.QSortFilterProxyModel"]
  3989152870["QtCore.QAbstractProxyModel"]
  1898060022["QtCore.QAbstractItemModel"]
  3984060476["QtCore.QObject"]
  37984305["Shiboken.Object"]
  2548039224 --> 2211274329
  2431222121 --> 2548039224
  3882849576 --> 2431222121
  3227531497 --> 3882849576
  2751680898 --> 3227531497
  153997648 --> 2548039224
  3989152870 --> 153997648
  1898060022 --> 3989152870
  3984060476 --> 1898060022
  37984305 --> 3984060476
  2751680898 --> 37984305

🛈 DocStrings

Bases: SortFilterProxyModel

Proxy model for filtering based on non-str values.

Sometimes it is needed to filter for non-str values, especially when it is required to filter based on a different role than DisplayRole.

Same as the Qt QSortFilterProxyModel, this proxy respects the filterRole and filterKeyColumn properties.

Source code in prettyqt/itemmodels/proxies/valuefilterproxymodel.py
class ValueFilterProxyModel(core.SortFilterProxyModel):
    """Proxy model for filtering based on non-str values.

    Sometimes it is needed to filter for non-str values, especially when it is required
    to filter based on a different role than DisplayRole.

    Same as the Qt QSortFilterProxyModel, this proxy respects the filterRole and
    filterKeyColumn properties.
    """

    ID = "value_filter"

    def __init__(self, filter_value=None, **kwargs):
        self._filter_value = filter_value
        super().__init__(**kwargs)

    def __repr__(self):
        return get_repr(self, self._filter_value)

    def filterAcceptsRow(self, source_row: int, parent: core.ModelIndex) -> bool:
        if self._filter_value is None:
            return True
        column = self.filterKeyColumn()
        role = self.filterRole()
        source_model = self.sourceModel()
        idx = source_model.index(source_row, column, parent)
        value = source_model.data(idx, role)
        return value == self._filter_value

    def set_filter_value(self, value):
        """Set the filter value."""
        self._filter_value = value
        self.invalidateRowsFilter()

    def get_filter_value(self):
        """Get the filter value."""
        return self._filter_value

    filter_value = core.Property(
        object,
        get_filter_value,
        set_filter_value,
        user=True,
        doc="Value to use for filtering",
    )

get_filter_value()

Get the filter value.

Source code in prettyqt/itemmodels/proxies/valuefilterproxymodel.py
def get_filter_value(self):
    """Get the filter value."""
    return self._filter_value

set_filter_value(value)

Set the filter value.

Source code in prettyqt/itemmodels/proxies/valuefilterproxymodel.py
def set_filter_value(self, value):
    """Set the filter value."""
    self._filter_value = value
    self.invalidateRowsFilter()

:fa-brands-github: Show source on GitHub